<template>
    <section>
        <!--搜索工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px; ">
            <el-form :inline="true" :model="filters" :rules="searchRules" ref="filters" label-width="80px">
                <el-form-item prop="year">
                    <el-select
                            placeholder="年份" v-model="filters.year" size="18px">
                        <el-option :key="item" :label="item" :value="item"
                                   v-for="item in options.years"></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item prop="check_unit">
                    <el-input
                            placeholder="院校名称"
                            v-model.trim="filters.check_unit">
                    </el-input>
                </el-form-item>

              <!--  <el-form-item prop="check_result">
                    <el-select
                            placeholder="检查结果" v-model="filters.check_result" size="18px">
                        <el-option :key="key" :label="item" :value="key"
                                   v-for="(item,key) in options.check_result"></el-option>
                    </el-select>
                </el-form-item>-->
                <el-form-item prop="group_user_name">
                    <el-input
                            placeholder="检查组组长"
                            v-model.trim="filters.group_user_name">
                    </el-input>
                </el-form-item>
                <el-form-item prop="check_report_status">
                    <el-select
                            placeholder="状态" v-model="filters.check_report_status" size="18px" >
                        <el-option :key="key" :label="item" :value="key"
                                   v-for="(item,key) in options.manager_report_status"></el-option>
                        <el-option :key="-1" label="全部" value="-1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search">搜索</el-button>
                    <el-button @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </el-col>


        <!--搜索结果表格-->
        <el-table
                :header-row-style="headerRowStyle"
                :data="tableData"
                stripe
                v-loading="listLoading"
                style="width: 100%;">
            <el-table-column
                    label="序号"
                    type="index"
                    width="70"
                    align="center">
            </el-table-column>
            <el-table-column
                    width="120"
                    align="right">
                <template slot-scope="scope">
                    <img v-if="scope.row.check_unit_logo" :src="scope.row.check_unit_logo.path" class="avatar">
                </template>
            </el-table-column>
            <el-table-column
                    label="高校名称"
                    prop="check_unit">
            </el-table-column>
           <!-- <el-table-column
                    align="center"
                    label="检查结果"
                    prop="check_result">

                <template slot-scope="scope">

                    <img v-if="scope.row.check_result" :src="'/assets/images/'+ dict.check_result_level[scope.row.check_result]" />
                    <span v-else style="color:#999">—</span>
                </template>
            </el-table-column>-->
            <el-table-column
                    align="center"
                    label="检查组组长"
                    prop="group_user_name">
            </el-table-column>
            <el-table-column
                    label="更新时间"
                    prop="gmt_modified">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="状态"
                    prop="check_report_status" :formatter="formatterStatus">
            </el-table-column>

            <el-table-column label="操作" align="left" width="200">
                <template slot-scope="scope">
                    <el-button
                            type="primary" plain=""
                            @click="view(scope.row.id)">详情
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <!--分页-->
        <el-col :span="24" class="toolbar">
            <el-pagination
                    style="text-align: center;"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :page-size="pager.page_size"
                    :page-sizes="pager.sizes"
                    background
                    :current-page="pager.page_current"
                    layout="prev,pager,next,sizes,total"
                    :total="pager.total">
            </el-pagination>
        </el-col>

    </section>
</template>

<script>
    import {getReportsList,getReportsDetail} from '../../api/report_manager_api'
    import dict from '../../common/js/dict';
    export default {
        name:'reportManageList',
        data() {
            return {
                dict:dict,
                currentYear: '2018',
                //表单header样式
                headerRowStyle: {
                    backgroundColor: "#ddd",
                    color: "#333",
                    textAlign: "center"
                },
                listLoading: false,
                //表格数据
                tableData: [],
                filters: {
                    year: '',
                    check_unit: '',
                    group_user_name:'',//组长
                    check_report_status:'',
                    check_result:''
                },
                searchRules:{
                    year:{required:true,message:'请选择年份',trigger:'blur'}
                },
                //分页设置
                pager: {
                    sizes: [10, 20, 30, 40, 50],
                    total: 0,
                    page_size: 10,
                    page_current: 1
                },
                options: {
                    years: [],
                    check_result: dict.check_result,
                    manager_report_status:dict.manager_report_status
                }
            }
        },
        methods: {
            formatCheckResult(row){
                if(row.check_result){
                    return dict.check_result[row.check_result];
                }else{
                    return '——';
                }
            },
            formatterStatus(row){
                if(row.check_report_status) {
                    return dict.manager_report_status[row.check_report_status];
                }else{
                    return '';
                }
            },

            // 详情
            view(id) {
                this.$router.push('/manage/reports/view/' + id);
            },
            //分页page_size发生改变
            handleSizeChange(val) {
                this.pager.page_current = 1;
                this.pager.page_size = val;
                this.getReports();
            },
            //分页page_current发生改变
            handleCurrentChange(val) {
                this.pager.page_current = val;
                this.getReports();
            },
            search(){
                this.pager.page_current = 1;
                this.getReports();
            },
            getReports(){
                this.$refs['filters'].validate((valid) => {
                    if (valid){

                        this.listLoading = true;  //显示loading

                        let condition = this.filters;
                        let params = {
                            page_size: this.pager.page_size,
                            page_current: this.pager.page_current,
                            order_column:"gmt_modified",
                            order_by:"desc",
                            condition: condition
                        };

                        getReportsList(params).then((res) => {
                            if (res.data.status == 200) {
                                this.listLoading = false;  //隐藏loading

                                let result = JSON.parse(res.data.datas);
                                this.tableData = result.items;
                                this.pager.total = result.total;
                            } else {
                                if (res.data.status == 401) {
                                    this.$router.push('/login');
                                }
                                this.$message.error(res.data.status + " " + res.data.msg);
                            }
                        });
                    }
                });

            },
            reset(){
                this.$refs['filters'].resetFields();
                this.pager.page_current = 1;
                this.filters.year = this.currentYear;
                this.getReports();
                },
            initYears() {
                this.currentYear = (new Date()).getFullYear()+'';
                this.filters.year = this.currentYear;

                for (let i = this.currentYear; i >= 2018; i--) {
                    this.options.years.push(i);
                }
            },
            //初始化页面
            initData() {
                this.initYears();
                this.getReports();
            }
        },
        mounted() {
            this.$nextTick(function () {
                this.initData();
            })
        }
    }
</script>

<style scoped>
.avatar{
    width:50px;
    height:50px;
    float:right;
}
</style>
